const mongoose = require('mongoose')

mongoose.connect('mongodb://localhost/qingtao')
    .then(()=>console.log('数据库连接成功'))
    .catch(error=>console.log(error))


const Iuser = new mongoose.Schema({
    //第一次使用手机号登陆时随机分配一个名称
    name:String,
    phone:{
        type:Number,
        required:true
    },
    //验证码 使用手机登陆时生成验证码发个客户端 然后由客户端发给服务然后进行对比
    verificationCode:String,
    //微信账号名
    account:String,
    //微信账号密码
    password:String,
    shoppingCart:{
        //数据关联可以为数组 populate() 传值也只需是 shoppingCart
        type:[mongoose.Schema.Types.ObjectId],
        //ref 表示要管理内容所在的集合
        ref:'Vegetable'
    },
    realName:{
        type:Boolean,
        default:false
    },
    address:String,
    headPortrait:String,
    ID:String,
    hometown:String,
    house:String
})

exports.User = mongoose.model('User',Iuser)

const Ibenner = new mongoose.Schema({
    picture:String
})

exports.Benner = mongoose.model('Benner',Ibenner)

const Ivegetable = new mongoose.Schema({
    name:{
        type:String,
        required:true
    },
    address:{
        type:String,
        required:true
    },
    price:{
        type:Number,
        required:true
    },
    beforePrice:Number,
    classification:[String],
    //总售出
    sold:{
        type:Number,
        default:0
    },
    //月售出
    monthlySale:{
        type:Number,
        default:0
    },
    //会员折扣
    memberDiscount:{
        type:Number,
        default:10
    },
    soldOut:{
        type:Boolean,
        default:false
    }
})

exports.Vegetable = mongoose.model('Vegetable',Ivegetable)
